using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;

namespace Kaleida.ServiceMonitor.Model.StructuredSource
{
    public class ScriptDefinition
    {
        private readonly IList<DirectiveDefinition> directives;
        private readonly IList<OperationDefinition> operations;
        private readonly IList<string> comments;

        public ScriptDefinition([NotNull] IList<DirectiveDefinition> directives, [NotNull] IList<OperationDefinition> operations, [NotNull] IList<string> comments)
        {
            if (directives == null) throw new ArgumentNullException("directives");
            if (operations == null) throw new ArgumentNullException("operations");
            if (comments == null) throw new ArgumentNullException("comments");

            this.directives = directives;
            this.operations = operations;
            this.comments = comments;
        }

        public IList<DirectiveDefinition> Directives
        {
            get { return directives; }
        }

        public IList<OperationDefinition> Operations
        {
            get { return operations; }
        }

        public IList<string> Comments
        {
            get { return comments; }
        }

        public override string ToString()
        {
            return string.Join("\r\n", operations.Select(i => i.ToString()));
        }
    }

    public class ScriptGroup
    {
        [CanBeNull]private readonly List<ScriptGroup> children;

        public ScriptGroup([NotNull] List<ScriptGroup> children)
        {
            if (children == null) throw new ArgumentNullException("children");
            this.children = children;
        }

        public IList<ScriptGroup> Children
        {
            get { return children; }
        }
    }
}